package com.yyds.yygh.hospclient.controller.api;

import com.yyds.yygh.common.result.Result;
import com.yyds.yygh.hospclient.service.DepartmentService;
import com.yyds.yygh.hospclient.service.HospitalService;
import com.yyds.yygh.hospclient.service.HospitalSetService;
import com.yyds.yygh.hospclient.service.ScheduleService;
import com.yyds.yygh.model.hosp.Hospital;
import com.yyds.yygh.model.hosp.Schedule;
import com.yyds.yygh.vo.hosp.DepartmentVo;
import com.yyds.yygh.vo.hosp.HospitalQueryVo;
import com.yyds.yygh.vo.hosp.ScheduleOrderVo;
import com.yyds.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "医院管理接口")
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation("获取分页列表")
    @GetMapping ("/{page}/{limit}")
    public Result selecthospital(@PathVariable Integer page,
                                 @PathVariable Integer limit,
                                 HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pages = hospitalService.selectPage(page, limit, hospitalQueryVo);

        return Result.success(pages);
    }
    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("/findByHosname/{hosname}")
    public Result findByHosname(@PathVariable String hosname){
        List<Hospital> hospitalList = hospitalService.findByHosname(hosname);
        return Result.success(hospitalList);
    }
    @ApiOperation("医院预约挂号详情")
    @GetMapping("/{hoscode}")
    public Result item(@PathVariable String hoscode){
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.success(map);
    }
    @ApiOperation("根据医院code查询子科室列表")
    @GetMapping("/department/{hoscode}")
    public Result index(@PathVariable String hoscode){
        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return Result.success(list);
    }
    @ApiOperation("获取可预约排班数据")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(@PathVariable int page,
                                         @PathVariable int limit,
                                         @PathVariable String hoscode,
                                         @PathVariable String depcode){
        Map<String, Object> result = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.success(result);
    }
    @ApiOperation("获取指定日期的排班数据")
    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable String hoscode,
                                   @PathVariable String depcode,
                                   @PathVariable String workDate){
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return Result.success(scheduleList);
    }
    @ApiOperation("根据排班id获取排班数据")
    @GetMapping("/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        Schedule schedule = scheduleService.getById(scheduleId);
        return Result.success(schedule);
    }
    @ApiOperation("根据排班id获取预约下单数据")
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
    @ApiOperation("获取医院签名信息")
    @GetMapping("/inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable String hoscode){
        return hospitalSetService.getSignInfoVo(hoscode);
    }
}
